/**
 * 候选人宽列表
 */
import React from 'react';
import { Table } from 'antd';
import { TableFilter } from '@/components';
import { getDisplayText } from '@/utils/dataDictUtil';
import { TalentMajorInfoCard } from './index';
import { renderPhone, renderShortDate, renderCandidateStatus, renderCandidateRecordOperate } from '../renderUtil';
import { CANDIDATE_STATUS } from '../dictionary';

const CandidateCardTable = ({
    loading,
    dataSource,
    condition,
    onJumpDetail,
    onRefresh,
    sortOrders,
    isPrincipal,
    isLauncher,
    channelDict,
    ...rest
}) => {
    const columns = [
        {
            title: <span style={{ marginLeft: '16px' }}>姓名</span>,
            dataIndex: 'talentName',
            render: (_, record) => (
                <div style={{ cursor: 'pointer' }}>
                    <TalentMajorInfoCard talent={record}></TalentMajorInfoCard>
                </div>
            )
        },
        {
            title: '手机',
            dataIndex: 'talentPhone',
            render: renderPhone
        },
        {
            title: '渠道',
            dataIndex: 'notesSource',
            filteredValue: condition.notesSource ? [condition.notesSource] : [],
            filters: channelDict,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: val => getDisplayText(channelDict, val)
        },
        {
            title: '推荐时间',
            dataIndex: 'recommendTime',
            sorter: () => {},
            sortOrder: sortOrders?.recommendTime || false,
            render: val => renderShortDate(val, 'MM-DD HH:mm')
        },
        {
            title: '状态',
            dataIndex: 'candidateStatus',
            filteredValue: condition.candidateStatus ? [condition.candidateStatus] : [],
            filters: CANDIDATE_STATUS,
            filterMultiple: false,
            filterDropdown: filterProps => <TableFilter {...filterProps} />,
            render: (val, record) => renderCandidateStatus(val, record.candidateStatusHover)
        },
        {
            title: '操作',
            dataIndex: 'action',
            onCell: () => ({
                onClick: e => {
                    e.stopPropagation();
                }
            }),
            render: (_, record) => renderCandidateRecordOperate(record, onRefresh, isPrincipal, isLauncher)
        }
    ];
    return (
        <>
            <Table
                {...rest}
                rowKey="id"
                bordered={false}
                columns={columns}
                loading={loading}
                dataSource={dataSource}
                pagination={false}
                onRow={record => ({
                    onClick: () => {
                        const { recruitTalentMatcherId, id } = record;
                        if (onJumpDetail) onJumpDetail(id, recruitTalentMatcherId, record);
                    }
                })}
            />
        </>
    );
};
export default CandidateCardTable;
